<template>
  <a-dropdown style="display: inline-block; height: 100%; vertical-align: initial">

    <a-dropdown>
      <div
        style="cursor: pointer"
        class="user-info"
      >
        <img
          class="avatar"
          :src="userInfo.avatar || require('@/assets/avatar.png')"
          @error="avatarError"
        />
        <div>
          <p>{{userInfo.usr_nickname}}</p>
          <!-- <p>{{userInfo.admin_info.s_a_nam}}</p> -->
          <p>{{userInfo.admin_info.pow_gp_nam}}</p>
        </div>
      </div>
      <a-menu slot="overlay">
        <a-menu-item
          key="0"
          @click="$router.push('/common/settings/base')"
        >
          个人信息
        </a-menu-item>
        <a-menu-divider />
        <a-menu-item
          key="3"
          @click="handleLogout"
        >
          退出登录
        </a-menu-item>
      </a-menu>
    </a-dropdown>
    <!-- <a-menu style="width: 150px" slot="overlay"> -->
    <!-- <a-menu-item>
        <a-icon type="user" />
        <span>个人中心</span>
      </a-menu-item>
      <a-menu-item>
        <a-icon type="setting" />
        <span>设置</span>
      </a-menu-item>
      <a-menu-divider /> -->
    <!-- <a-menu-item @click="handleLogout">
        <a-icon type="logout" />
        <span>退出登录</span>
      </a-menu-item> -->
    <!-- </a-menu> -->
  </a-dropdown>
</template>

<script lang="ts">
import { Vue, Mixins, Component } from 'vue-property-decorator'
import RootMixin from '@/mixin'
import store from '@/store'
import { getModule } from 'vuex-module-decorators'
import { userModule } from '@/store/modules/user'

@Component
export default class HeaderAvatar extends Mixins(RootMixin) {
  get userInfo() {
    return userModule.userInfo
  }

  public handleLogout() {
    const options: any = {
      title: '确定退出当前账号？',
      onOk: () => {
        userModule.userLogout()
      }
    }
    this.$confirm(options)
  }

  public avatarError(e: any) {
    console.log('avatarError', e)
  }
}
</script>

<style lang="less" scoped>
.avatar {
  width: 30px;
  height: 30px;
  // margin: 17px 8px 20px 0;
  margin: 0 10px;
  vertical-align: middle;
  border-radius: 50%;
}
.user-info {
  display: flex !important;
  align-items: center;
  p {
    line-height: 1.5;
    margin-bottom: 0;
    text-align: center;
  }
}
</style>
